import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomFile } from '@/shared/model/room-file.model';
import RoomFileService from './room-file.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomFileDetails extends Vue {
  @Inject('roomFileService') private roomFileService: () => RoomFileService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomFile: IRoomFile = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomFileId) {
        vm.retrieveRoomFile(to.params.roomFileId);
      }
    });
  }

  public retrieveRoomFile(roomFileId) {
    this.roomFileService()
      .find(roomFileId)
      .then(res => {
        this.roomFile = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
